/**
 * 首页JS交互 
 */
/*
var tag = true;
var theHideMenu = function(obj, tag){
	if(tag){
		obj.removeClass("hover"); //删除获取焦点时的样式
		obj.next(".i_c_tips").hide(); //隐藏提示框
	}
}
*/


function addListener(element, e, fn) {
	if (element.addEventListener) {
		element.addEventListener(e, fn, false);
	} else {
		element.attachEvent("on" + e, fn);
	}
}

$(function(){
	//分类列表
/*	$("#categoryList > dl.item").mouseenter(function() {//设置当前所选项的鼠标滑过事件
		$("#categoryList > dl.item").removeClass('hover').next(".i_c_tips").hide();
		var objL = $(this); //获取当前对象
		var curY = objL.position().top;
		var curW = objL.outerWidth();
		
		objL.addClass("hover"); //增加获取焦点时的样式
		objL.next(".i_c_tips").show().css({"top":curY, "left":curW}); //显示并设置提示框的坐标
	}).mouseleave(function() {//设置当前所选项的鼠标移出事件
		objL = $(this);
		objL.next(".i_c_tips").mouseenter(function(){
			tag = false;
			objL.addClass("hover");
		}).mouseleave(function(){
			tag = true;
			objL.removeClass("hover");
			$(this).hide();
		});
		setTimeout('theHideMenu(objL, tag)', 1);
	});*/
	
	//热门学校列表切换
	$("#toplistTab").find("li").click(function(){
		var cobj = $(this);
		$("#toplistTab").find("li").removeClass('curr');
		cobj.addClass('curr');
		var tid = cobj.attr('tid');
		$(".cons_sub").hide();
		$("#toplist_"+tid).show();
	});

	/**
	 * 导航分类栏方法
	 */
	$('.mn_sort > .mn_mc > .item').hover(function(){
		$(this).addClass('item_hover');
		$(this).children('.i_bd').show();
	},function(){
		$(this).removeClass('item_hover');
		$(this).children('.i_bd').hide();
	});
	/**
	 * 联系方式模块微信二维码
	 */
	$('.weixin').hover(function(){
		$(this).find('.erweima').show();
	},function(){
		$(this).find('.erweima').hide();
	});

	/**
	 *页面用JS，含搜索，侧边栏滚动
	 */
	$("#head_searchSubmit").mouseover(function(){
		$(this).parent().addClass('tp_txt_focus');
	}).mouseleave(function(){
		$(this).parent().removeClass('tp_txt_focus');
	});
	$(".topR_search").inputTips();
	$("#head_searchKeywords").prev("span.iptTips").css({"left":"1px", "top":"0px"});

	$("#searchType").click(function(){
		var obj = $(this);
		var pobj = $("#searchTypeList");
		var course = $("#courseType").clone();
		var school = $("#schoolType").clone();
		obj.showMenu('#searchTypeList');
		obj.mouseout(function(){
			obj.hideMenu('#searchTypeList');
		});

		pobj.find("a").click(function(){
			var cobj = $(this);
			obj.attr('stype', cobj.attr('stype')).html(cobj.text()+'<i class="icoR icoR_5"></i>');
			if(cobj.attr('stype') == 'school'){
				$("#courseType").remove();
				$("#schoolType").after(course);
			} else {
				$("#schoolType").remove();
				$("#courseType").after(school);
			}
			pobj.hide();
		});
	});

	$("#head_searchKeywords").keydown(function(event){
		if(event.keyCode == 13){
			$("#head_searchSubmit").trigger('click');
		}
	});

	/**
	 * 发起搜索逻辑
	 */
	$("#head_searchSubmit").click(function(){
		var keywords = $.trim($("#head_searchKeywords").val()),
			searchType = $("#searchType").attr('stype');
		if(searchType == "course"){
			if(keywords == ''){
				searchUrl = "/course/index.html";
			}else{
				searchUrl = "/course/_"+encodeURIComponent(keywords)+"_____.html";
			}
		}else{
			searchUrl = "/?mod=search&act=school&keyword="+encodeURIComponent(keywords);
		}
		document.location.href = searchUrl;
		return false;
	});
	$(window).scroll(function(){
		if ($(window).scrollTop()>100){
			$("li.r_gotop").fadeIn(750);
		}else{
			$("li.r_gotop").fadeOut(750);
		}
	});
	addListener(document, "mouseover",function(evt) {
		var evt = window.event ? window.event: evt,
			target = evt.srcElement || evt.target;
		if(target.id == "btnWeixin") {
			$("#btnWeixin").animate({left: '-66px'}, "fast");
			return;
		}else if(target.id == "btnFeedback"){
			$("#btnFeedback").animate({left: '-66px'}, "fast");
			return;
		}else if(target.id == "btnGotop"){
			$("#btnGotop").animate({left: '-66px'}, "fast");
			return;
		}else if(target.id == "customerService"){
			$("#customerService").animate({left: '-66px'}, "fast");
			return;
		}
	});
	addListener(document, "mouseout",function(evt) {
		var evt = window.event ? window.event: evt,
			target = evt.srcElement || evt.target;
		if(target.id == "btnWeixin") {
			$("#btnWeixin").stop(true).animate({left: '0px'}, "fast");
			return;
		}else if(target.id == "btnFeedback"){
			$("#btnFeedback").stop(true).animate({left: '0px'}, "fast");
			return;
		}else if(target.id == "btnGotop"){
			$("#btnGotop").stop(true).animate({left: '0px'}, "fast");
			return;
		}else if(target.id == "customerService"){
			$("#customerService").stop(true).animate({left: '0px'}, "fast");
			return;
		}
	});

	$("#weixinClose").click(function(){
		$("#weixinCodeImg").hide();
		$("#btnWeixin").css("display","block");
	});
	$("#btnWeixin").click(function(){
		$("#btnWeixin").css("display","none");
		$("#weixinCodeImg").show();
	})
	/*with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://img.baidu.com/hunter/chuanke.js?st='+~(new Date()/864e5)];*/
});